package Homework.Homework04;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RiviseStudent {
    List<Student> list = new ArrayList<>();
    public static void riviseStudent(List<Student> list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入修改学生信息的学号");
        Integer updID = sc.nextInt();
        int index = -1;
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            if (updID.equals(s.getID())) {
                index = i;
            }
        }
        if (index == -1) {
            System.out.println("你要修改的学生不存在，请重新操作");
        } else {
            System.out.println("请输入学号");
            int id = sc.nextInt();
            System.out.println("请输入姓名");
            String name = sc.nextLine();
            System.out.println("请输入年龄");
            Integer age = sc.nextInt();
            Student student = new Student();
            student.setID(id);
            student.setName(name);
            student.setAge(age);
            list.add(student);
            list.set(index, student);
            System.out.println("修改信息成功！");
        }
    }
}